/*
** 1519.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Thu Sep 25 21:12:14 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/* #include "1519.h" */
#include <stdio.h>

int main()
{
     int root;
     char tmp[10000];		/* Pridict: less than 100 bits
				 * now we have to increase... */
     int i;

     while(scanf("%s", tmp)){
	  if (tmp[0] == '0') break;
	  root = 0;
	  for(i = 0; tmp[i] != '\0'; i++)
	       root += tmp[i] - '0';
	  while(root >= 10){
	       tmp[0] = root / 10000;
	       tmp[1] = root % 10000 /1000;
	       tmp[2] = root % 1000 / 100;
	       tmp[3] = root % 100 / 10;
	       tmp[4] = root % 10;
	       root = tmp[0] + tmp[1] + tmp[2] + tmp[3] + tmp[4];
	  }
	  printf("%d\n", root);
     }
     return 0;
}

